package es.capgemini.extjsplugin.wizard;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.swt.widgets.TableItem;

import es.capgemini.extjsplugin.ui.AttributesSelectionPanel;
import es.capgemini.extjsplugin.ui.ExtendedField;

public class AttributesCellModifier implements ICellModifier{
	AttributesSelectionPanel attributesSelectionPanel;
	public AttributesCellModifier(AttributesSelectionPanel attributesSelectionPage) {
		super();
		this.attributesSelectionPanel=attributesSelectionPage;
	}
	
	@Override
	public boolean canModify(Object arg0, String property) {
		int columnIndex = attributesSelectionPanel.getColumnNames().indexOf(property);
		if(columnIndex==0)
			return true;
			
		return false;
	}

	@Override
	public Object getValue(Object element, String property) {
		int columnIndex = attributesSelectionPanel.getColumnNames().indexOf(property);
		Object result = null;
		ExtendedField field = (ExtendedField) element;
		switch(columnIndex){
			case 0:
				result=field.getIncluded();
				break;
			case 1:
				result=field.getField().getName();
				break;
			case 2:
				result=field.getField().getType();
				break;
				
		}
		return result;
		
	}

	@Override
	public void modify(Object element, String property, Object value) {
		int columnIndex = attributesSelectionPanel.getColumnNames().indexOf(property);
		TableItem tableItem=(TableItem)element;
		
		ExtendedField field = (ExtendedField) tableItem.getData();
		switch(columnIndex){
			case 0:
				field.setIncluded((Boolean)value);
				break;
			case 1:
				//result=field.getField().getName();
				break;
			case 2:
				//result=field.getField().getType();
				break;
				
		}
		attributesSelectionPanel.getTableViewer().update(field, null);
		
	}

}
